package com.cskaoyan.app.util;

import com.cskaoyan.app.bean.po.MarketCart;
import com.cskaoyan.app.bean.po.MarketCartExample;
import com.cskaoyan.app.bean.vo.CartDataVo;
import com.cskaoyan.app.bean.vo.CartTotalVo;

import java.util.List;

/**
 * @Author: 廖平安
 * @CreateTime: 2023-01-01  00:22
 * @Description: TODO
 * @Version: 1.0
 */
public class CartTotalUtil {
//private CartTotalVo cartTotalVo;
    public static CartTotalVo getData(List<MarketCart> list) {
        Double checkedGoodsAmount = 0.0;
        Double goodsAmount = 0.0;
        Integer checkedGoodsCount = 0;
        Integer goodsCount = 0;
        Integer number;
        Double price;
        for (MarketCart cart : list) {
            number = cart.getNumber().intValue();
            price = cart.getPrice().doubleValue();
            if (cart.getChecked()) {
                checkedGoodsAmount += number * price;
                checkedGoodsCount+=number;
            }
            goodsAmount += number * price;
            goodsCount+=number;
        }
        return new CartTotalVo(goodsCount, checkedGoodsCount, goodsAmount, checkedGoodsAmount);
    }
}
